package com.ideal.response;

import java.io.Serializable;

/**
 * <h1> 通用 RESP </h1>
 *
 * @author ideal-20
 * @date 2023-08-05 02:04
 **/
public class BaseResponse<T> implements Serializable {
    private int code;
    private T data;
    private String message;

    public BaseResponse() {
        this.code = 0;
        this.message = "success";
    }

    public BaseResponse(T data) {
        this.code = 0;
        this.data = data;
        this.message = "success";
    }

    public BaseResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static <T> BaseResponse<T> success() {
        return new BaseResponse<>();
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(data);
    }

    public static <T> BaseResponse<T> fail(String message) {
        return new BaseResponse<>(-1, message);
    }

    public boolean isSuccess() {
        return code == 0;
    }


    @Override
    public String toString() {
        return "BaseResponse{" +
                "code=" + code +
                ", data=" + data +
                ", message='" + message + '\'' +
                '}';
    }
}

